package com.github.cakin.shiro.chapter18.entity;

import java.io.Serializable;

/**
 * @className: Organization
 * @description: 组织节点
 * @date: 2020/5/25
 * @author: cakin
 */
public class Organization implements Serializable {
    /**
     * 编号
     */
    private Long id;
    /**
     * 组织机构名称
     */
    private String name;
    /**
     * 父编号
     */
    private Long parentId;
    /**
     * 父编号列表，如1/2/
     */
    private String parentIds;
    /**
     * 是否可用
     */
    private Boolean available = Boolean.FALSE;


    public Long getId() {
        return id;
    }

    public void setId( Long id ) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName( String name ) {
        this.name = name;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId( Long parentId ) {
        this.parentId = parentId;
    }

    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds( String parentIds ) {
        this.parentIds = parentIds;
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable( Boolean available ) {
        this.available = available;
    }

    public boolean isRootNode() {
        return parentId == 0;
    }

    public String makeSelfAsParentIds() {
        return getParentIds() + getId() + "/";
    }

    @Override
    public boolean equals( Object o ) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Organization that = (Organization) o;

        if (id != null ? !id.equals(that.id) : that.id != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "Organization{"
                + "id=" + id
                + ", name='" + name + '\''
                + ", parentId=" + parentId
                + ", parentIds='" + parentIds + '\''
                + ", available=" + available
                + '}';
    }
}
